/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import abstractmodel.InfoValue;
import java.text.DateFormat;

/**
 *
 * @author fightfxj
 */
public class CreditCardAccountInfo implements abstractmodel.IInfo {
    
    private String accountName;           //帐户名称 长度不超过20 的字符串
    private String bankName;               // 归属银行 长度不超过20 的字符串
    private String accountNumber;        //卡号 长度不超过40 的字符串
    private String userName;                //开户名 长度不超过20 的字符串
    private Double limit;                      //额度
    private String availableTimeString;   //时间，直接采用String形式对外表示
    private String payTimeString;   //时间，直接采用String形式对外表示
    private String billTimeString;   //时间，直接采用String形式对外表示
    private DateFormat availableTime;   //有效日期
    private DateFormat payTime;            //还款日期dd 格式，0~31 之间的整数
    private DateFormat billTime;             //帐单日dd 格式，0~31 之间的整数
    public static String[] titles = new String[]{"帐户名称", "归属银行", "卡号", "开户名", "额度", "有效日期", "还款日期", "帐单日"};
    private int id;

    public CreditCardAccountInfo() {
        accountName = new String("信用卡账户名称");
        bankName = new String("归属银行");
        accountNumber = new String("000000");
        userName = new String("开户名");
        limit = new Double(0);
        availableTimeString = new String();
        payTimeString = new String();
        billTimeString = new String();
        availableTime = DateFormat.getDateTimeInstance();
        payTime = DateFormat.getDateTimeInstance();
        billTime = DateFormat.getDateTimeInstance();
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public String getAvailableTimeString() {
        return availableTimeString;
    }

    public String getBillTimeString() {
        return billTimeString;
    }
  
    public String getAccountName() {
        return accountName;
    }

    public String getAccountNunber() {
        return accountNumber;
    }

    public DateFormat getAvailableTime() {
        return availableTime;
    }

    public String getBankName() {
        return bankName;
    }

    public DateFormat getBillTime() {
        return billTime;
    }

    public double getLimit() {
        return limit;
    }

    public DateFormat getPayTime() {
        return payTime;
    }

    public String getUserName() {
        return userName;
    }

    @Override
    public String[] getTitles() {
        return CreditCardAccountInfo.titles;
    }

    @Override
    public InfoValue getValue(String title) {
        InfoValue iv = new InfoValue();
        iv.setType(this.getClass());
        if (title.equals("帐户名称")) {
            iv.setObj(this.accountName);
            iv.setType(String.class);
        }
        else if (title.equals("归属银行")) {
            iv.setObj(this.bankName);
            iv.setType(String.class);
        }   
        else if (title.equals("卡号")) {
            iv.setObj(this.accountNumber);
            iv.setType(String.class);
        }   
        else if (title.equals("开户名")) {
            iv.setObj(this.userName);
            iv.setType(String.class);
        }   
        else if (title.equals("额度")) {
            iv.setObj(this.limit);
            iv.setType(Double.class);
        }   
        else if (title.equals("有效日期")) {
            iv.setObj(this.availableTimeString);
            iv.setType(String.class);
        }  
        else if (title.equals("还款日期")) {
            iv.setObj(this.payTimeString);
            iv.setType(String.class);
        }
        else if (title.equals("帐单日")) {
            iv.setObj(this.billTimeString);
            iv.setType(String.class);
        }
        else if (title.equalsIgnoreCase("id")) {
            iv.setObj(new Integer(this.id).toString());
            iv.setType(String.class);
        }        
        return iv;
    }

    @Override
    public boolean setValue(String title, Object value) {
       if (title.equals("帐户名称")) {
            this.accountName = value.toString();
        }
        else if (title.equals("归属银行")) {
            this.bankName = value.toString();
        }   
        else if (title.equals("卡号")) {
            this.accountNumber = value.toString();
        }   
        else if (title.equals("开户名")) {
            this.userName  = value.toString();
        }   
        else if (title.equals("额度")) {
            this.limit = new Double(value.toString()).doubleValue();
        }   
        else if (title.equals("有效日期")) {
            try {
                this.availableTime = DateFormat.getDateInstance();
                this.availableTime.getCalendar().setTime(configure.Global.sdf.parse(value.toString()));
                this.availableTimeString = value.toString();
            } catch (Exception e) {
                System.out.println("Exception in set time of BankAccountInfo");
            }
        }  
        else if (title.equals("还款日期")) {
            try {
                this.payTime = DateFormat.getDateInstance();
                this.payTime.getCalendar().setTime(configure.Global.sdf.parse(value.toString()));
                this.payTimeString = value.toString();
            } catch (Exception e) {
                System.out.println("Exception in set time of BankAccountInfo");
            }
        }
        else if (title.equals("帐单日")) {
            try {
                this.billTime  = DateFormat.getDateInstance();
                this.billTime.getCalendar().setTime(configure.Global.sdf.parse(value.toString()));
                this.billTimeString = value.toString();
            } catch (Exception e) {
                System.out.println("Exception in set time of BankAccountInfo");
            }
        } 
        ModelFactory.data.saveUser(ModelFactory.ur);
        return true;
    }

    @Override
    public int getid() {
        return this.id;
    }

    @Override
    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int getType() {
        return configure.Global.CREDITCARD_ACCOUNT_INFO_TYPE;
    }

}
